package com.yeyuanqi.hottop.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yeyuanqi.hottop.entity.Comment;
import com.yeyuanqi.hottop.vo.PageComment;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
* @author yeyuanqi
* @description 针对表【comment】的数据库操作Mapper
* @createDate 2022-03-01 23:35:13
* @Entity generator.entity.Comment
*/
@Mapper
public interface CommentMapper extends BaseMapper<Comment> {

    /**
     * 根据创建时间倒序 根据博客id和父评论id查询所有子评论
     */
    @Select("select id, nickname, content, avatar, create_time, is_admin_comment,parent_comment_nickname  from comment where parent_comment_id='-1' and is_published=1 order by create_time desc")
    List<PageComment> getPageCommentListByPageAndParentCommentIdByDesc();

    /**
     * 根据博客id和父评论id查询所有子评论
     */
    @Select("select id, nickname, content,avatar, create_time, is_admin_comment,parent_comment_nickname  from comment where parent_comment_id=#{parentCommentId} and is_published=1  order by create_time")
    List<PageComment> getPageCommentListByPageAndParentCommentId(@Param("parentCommentId") long parentCommentId);
}
